package xxl.robotlegs.extensions.commandcenter.impl 
{
	import xxl.robotlegs.extensions.commandcenter.api.ICommandConfigurator;
	import xxl.robotlegs.extensions.commandcenter.api.ICommandMapper;
	import xxl.robotlegs.extensions.commandcenter.api.ICommandMapping;
	import xxl.robotlegs.extensions.commandcenter.api.ICommandMappingList;
	import xxl.robotlegs.extensions.commandcenter.api.ICommandUnmapper;
	
	/**
	 * ...
	 * @author XXL
	 */
	public class CommandMapper implements ICommandMapper, ICommandUnmapper, ICommandConfigurator
	{
		private var _mappings:ICommandMappingList;
		private var _mapping:ICommandMapping;
		
		public function CommandMapper(mappings:ICommandMappingList) 
		{
			_mappings = mappings;
		}
		
		/* INTERFACE xxl.robotlegs.extensions.commandcenter.api.ICommandMapper */
		
		public function toCommand(commandClass:Class):ICommandConfigurator 
		{
			_mapping = new CommandMapping(commandClass);
			_mappings.addMapping(_mapping);
			return this;
		}
		
		/* INTERFACE xxl.robotlegs.extensions.commandcenter.api.ICommandUnmapper */
		
		public function fromCommand(commandClass:Class):void 
		{
			_mappings.removeMappingFor(commandClass);
		}
		
		public function fromAll():void 
		{
			_mappings.removeAllMappings();
		}
		
		/* INTERFACE xxl.robotlegs.extensions.commandcenter.api.ICommandConfigurator */
		
		public function withExecuteMethod(name:String):ICommandConfigurator 
		{
			_mapping.setExecuteMethod(name);
			return this;
		}
		
		public function withGuards(...guards):ICommandConfigurator 
		{
			_mapping.addGuards.apply(null, guards);
			return this;
		}
		
		public function withHooks(...hooks):ICommandConfigurator 
		{
			_mapping.addHooks.apply(null, hooks);
			return this;
		}
		
		public function once(value:Boolean = true):ICommandConfigurator 
		{
			_mapping.setFireOnce(value);
			return this;
		}
		
		public function withPayloadInjection(value:Boolean = true):ICommandConfigurator 
		{
			_mapping.setPayloadInjectionEnabled(value);
			return this;
		}
		
	}

}